package com.aifast.system.sys.service;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;

import com.aifast.common.global.Const;
import com.aifast.common.layui.LayuiDataTable;
import com.aifast.common.layui.LayuiPageFactory;
import com.aifast.system.sys.dao.SysMessageUserDao;
import com.aifast.system.sys.entity.SysMessageUser;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author fujian
 * @since 2022/10/19 16:49
 */
@Service
@RequiredArgsConstructor
public class SysMessageUserService extends ServiceImpl<SysMessageUserDao, SysMessageUser> {
    private final SysMessageUserDao dao;

    public LayuiDataTable list(String userId, Integer messageId, String read, String sendTime, Page pg) {
        String begin =null,end = null;
        List<Integer> users = new ArrayList<>();
        if(StrUtil.isNotBlank(userId)){
            users = Convert.toList(Integer.class,userId.split(Const.SYMBOL_COMMA));
        }
        if(StrUtil.isNotBlank(sendTime)){
            String[] strings = sendTime.split(" - ");
            begin = strings[0];
            end = strings[1];
        }

        return LayuiPageFactory.init(page(pg, dao.select(users,messageId,read,begin,end)));
    }

    @InterceptorIgnore(tenantLine = "true")
    public boolean batchInsert(List<SysMessageUser> entityList){
        return saveBatch(entityList);
    }

}
